<?php

namespace App\Trip\DealStr;

use Illuminate\Support\Str;

/**
 * 隐藏字符串的部分字符
 */
class HidePartOfString
{
    private string $string;

    public function __construct(string $string)
    {
        $this->string = $string;
    }

    public function explode($glue = ""): array
    {
        return explode($glue, $this->string);
    }

    public function hide(int $start = 0, int $end = 0, string $char = "*"): array|string
    {
        $count = $this->length() - $start - $end;
        $str   = str_repeat($char ?: '*', $count);
        return Str::substrReplace($this->string, $str, $start, $count);
    }

    private function length(): bool|int
    {
        return mb_strlen($this->string);
    }

}